﻿using System;
using System.Data;
using System.Data.Common;

namespace nkstdgia.common.ThamDinhGia.DataAccess
{
    public class Data
    {
        /// <summary>
        /// "System.Data.SqlClient"
        /// </summary>
        public static string dataProvider = "";//ConfigurationManager.ConnectionStrings["ConnectionString"].ProviderName;
        public static DbProviderFactory factory; //= DbProviderFactories.GetFactory(dataProvider);
        public static string ConnectionString = "";//ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        public static void setConnectionString(String dataProvider, string ConnectionString)
        {
            Data.dataProvider = dataProvider;
            Data.ConnectionString = ConnectionString;
            Data.factory = DbProviderFactories.GetFactory(dataProvider);
        }

        #region parameters

        public static DbParameter CreateParameter(string ParameterName, DbType ParameterType, int ParameterSize)
        {
            DbParameter p = factory.CreateParameter();
            p.ParameterName = ParameterName;
            p.DbType = ParameterType;
            p.Size = ParameterSize;
            return p;
        }

        public static DbParameter CreateParameter(string ParameterName, object ParameterValue)
        {
            DbParameter p = factory.CreateParameter();
            p.ParameterName = ParameterName;
            p.Value = ParameterValue;
            return p;
        }

        public static DbParameter CreateParameter(string ParameterName)
        {
            DbParameter p = factory.CreateParameter();
            p.ParameterName = ParameterName;
            return p;
        }

        #endregion parameters
    }
}